unit scnADLogin;

interface

uses
  Classes, SysUtils, IWAppForm, IWApplication, IWColor, IWTypes, Controls,
  IWVCLBaseControl, IWBaseControl, IWBaseHTMLControl, IWControl,
  IWCompButton, IWCompEdit, IWCompLabel, IWCompListbox, Forms,
  IWVCLBaseContainer, IWContainer, IWHTMLContainer, IWRegion, jpeg,
  IWExtCtrls, IWHTMLControls, IWHTML40Container;

type
  TfrmADLogin = class(TIWAppForm)
    btnValidate: TIWButton;
    IWLabel1: TIWLabel;
    IWLabel2: TIWLabel;
    edUser: TIWEdit;
    edPass: TIWEdit;
    btnExit: TIWButton;
    IWLabel6: TIWLabel;
    IWLabel8: TIWLabel;
    IWLabel10: TIWLabel;
    btnHelp: TIWButton;
    IWLabel4: TIWLabel;
    edDomain: TIWEdit;
    procedure btnExitClick(Sender: TObject);
    procedure btnValidateClick(Sender: TObject);
    procedure btnHelpClick(Sender: TObject);
    procedure IWAppFormCreate(Sender: TObject);
  public
  end;

implementation
 uses  ServerController;
{$R *.dfm}

procedure TfrmADLogin.btnExitClick(Sender: TObject);
begin
   WEbApplication.Terminate;
end;

procedure TfrmADLogin.btnValidateClick(Sender: TObject);

var
  su,sd,sp,sUT : string;
begin
    UserSession.bAuth := True;

    with UserSession do
    begin
      su := eduser.text;
      sp := edpass.text;
      sd := edDomain.Text;
      if AuthUser(su,sd,sp) then
      begin
        sUser := UpperCase(eduser.text);

        iwlabel6.caption := 'You have Authenticated :) !!!';

        GetUser(sUser);  // Internal function to validate user against
                         // application user setup - will update bAuth variable

      end
      else
      begin
        iwlabel6.caption := 'You are not Authenticated :( ';
        bAuth := False;
      end;

      if bAuth then
      begin

         IWLabel4.caption := 'Valid';
      end
      else
      begin
         IWLabel4.caption := 'User not Valid for APP';


      end;
   end;
end;

procedure TfrmADLogin.btnHelpClick(Sender: TObject);
begin
  AddToInitProc('NewWindow(''' + 'http://intranet/applicationhelp.HTM' + ''', ''Help'', '''');');
end;

procedure TfrmADLogin.IWAppFormCreate(Sender: TObject);
begin
     UserSession.sUSer := Webapplication.Request.CookieFields.Values['UserName'];
     // Original App uses cookies to store a value on machine and then lookup user

end;

initialization
   TfrmADLogin.SetAsMainForm;
end.
